package cjq.demo.thread.ch6_2;

import java.util.concurrent.ConcurrentLinkedDeque;

/**
 * Created by Administrator on 2016/5/3.
 */
public class Main {
    public static void main(String[] args) {
        ConcurrentLinkedDeque<String> list = new ConcurrentLinkedDeque<>();

        Thread threads[] = new Thread[100];
        for (int i = 0; i < threads.length; i++) {
            AddTask task = new AddTask(list);
            threads[i] = new Thread(task);
            threads[i].start();
        }
        System.out.println("Main: "+threads.length+" AddTask threads have bean launched");

        for (int i = 0; i < threads.length; i++) {
            try{
                threads[i].join();
            }catch(InterruptedException e){
                e.printStackTrace();
            }

        }
        System.out.println(" Main : Size of the List : "+list.size());

        for (int i = 0; i < threads.length; i++) {
            PollTask task = new PollTask(list);
            threads[i] = new Thread(task);
            threads[i].start();
        }
        System.out.println("Main: "+threads.length+" PollTask threads have been launched ");

        for (int i = 0; i < threads.length; i++) {
            try{
                threads[i].join();
            }catch (InterruptedException e){
                e.printStackTrace();
            }

        }
        System.out.println("Main : Size of the List: "+list.size());
    }
}
